package com.qf.service.impl;

import com.netflix.discovery.converters.Auto;
import com.qf.po.Orderinfo;
import com.qf.repository.OrderRepository;
import com.qf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderRepository orderRepository;
    @Override
    public Orderinfo add(Orderinfo orderinfo) {
        Orderinfo save = orderRepository.save(orderinfo);
        if (!ObjectUtils.isEmpty(save)){
            return save;
        }
        return null;
    }

    @Override
    public boolean del(Integer oid) {
        try {
            orderRepository.deleteById(oid);
            return true;
        }catch (Exception e){
            return false;
        }
    }

    @Override
    public Orderinfo update(Orderinfo orderinfo) {
        Orderinfo orderinfo1 = orderRepository.saveAndFlush(orderinfo);
        if (!ObjectUtils.isEmpty(orderinfo1)){
            return orderinfo1;
        }
        return null;
    }
}
